package thread.sync3;

public class Foo {
    //synchronized（同步监视器对象）建议不要用字面量，会影响其他线程
    //情况2
    public  static void doSomething(){
        synchronized (Foo.class) {
            Thread t=Thread.currentThread();
            System.out.println(t.getName()+":正在执行dosome方法...");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            System.out.println(t.getName()+":执行doseme方法完毕！");
        }
    }
    /*情况1：
    public synchronized static void doSomething(){
        Thread t=Thread.currentThread();
        System.out.println(t.getName()+":正在执行dosome方法...");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
        }
        System.out.println(t.getName()+":执行doseme方法完毕！");
    }

     */
}

